var i;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var EventManager = require("AA_EventManager");
var ResKeeper = require("AA_ResKeeper");
var CommonUtils = require("AA_CommonUtils");
var EvenType = require("AA_EvenType");
var Excel = require("AA_Excel");
var BuffMag = require("AA_BuffMag");
var UI_SkillItem = require("AA_UI_SkillItem");
var _decorator = cc._decorator;
var _ccclass = _decorator.ccclass;
var _property = _decorator.property;

var _def_UI_SkillShow = function (e) {
  function _creator() {
    var t = null !== e && e.apply(this, arguments) || this;
    t.tipView = null;
    t.rolelevel = null;
    t.progress = null;
    t.nowscallvView = null;
    t.nowshoId = -1;
    return t;
  }
  __extends(_creator, e);
  _creator.prototype.onEnable = function () {
    this.tipView.active = false;
    this.nowscallvView = this.node.getChildByName("New ScrollView").getComponent(cc.ScrollView);
    this.onAddListener();
    EventManager.EventMgr.addEventListener(EvenType.EVENT_TYPE.Game_Hide, this.closeTipView, this);
    EventManager.EventMgr.addEventListener(EvenType.EVENT_TYPE.HIDE_CLICK, this.onCode, this);
    EventManager.EventMgr.addEventListener(EvenType.EVENT_TYPE.Game_Add_CiTiao, this.onAddListener, this);
  };
  _creator.prototype.onCode = function (e) {
    1 == e && this.closeTipView();
  };
  _creator.prototype.closeTipView = function () {
    this.nowshoId = -1;
    this.tipView.active = false;
  };
  _creator.prototype.onAddListener = function () {
    var e = this;
    var t = BuffMag.BuffMgr.ciTiaoData;
    var o = {};
    for (var n = 0; n < t.length; n++) {
      var i = t[n];
      var a = o[i.id];
      a || (a = {
        id: i.id
      });
      var r = a.count;
      r || (r = 0);
      r += 1;
      a.count = r;
      o[i.id] = a;
    }
    var c = Object.keys(o);
    var s = this.nowscallvView.content.children;
    s.forEach(function (e) {
      e.active = false;
    });
    for (n = 0; n < c.length; n++) {
      var u = o[c[n]];
      var l = s[n];
      if (!l) {
        l = cc.instantiate(s[0]);
        this.nowscallvView.content.addChild(l);
      }
      l.active = true;
      l.getComponent(UI_SkillItem.default).initView(u, this.onClickItem.bind(this));
    }
    this.scheduleOnce(function () {
      e.nowscallvView.scrollToBottomRight(.2);
    }, .5);
    this.tipView.active = false;
    this.nowshoId = -1;
  };
  _creator.prototype.onClickItem = function (e) {
    if (e.nowdata.id != this.nowshoId) {
      var t = e.node.convertToWorldSpaceAR(cc.v2());
      t = this.node.parent.convertToNodeSpaceAR(t);
      this.tipView.x = t.x;
      this.tipView.y = t.y + 200;
      var o = this.node.parent.width - 380;
      this.tipView.x + this.tipView.width / 2 > o / 2 && (this.tipView.x = o / 2 - (this.tipView.width / 2 + 20));
      this.tipView.x - this.tipView.width / 2 < -o / 2 && (this.tipView.x = -(o / 2 - (this.tipView.width / 2 + 20)));
      this.tipView.getChildByName("jiantou").x = t.x - this.tipView.x;
      var n = Excel.Excel.shuiguocitiao(e.nowdata.id);
      var i = this.tipView.getChildByName("layout").getChildByName("lb").getComponent(cc.RichText);
      var a = this.tipView.getChildByName("layout").getChildByName("layout").getChildByName("count").getComponent(cc.Label);
      var r = Excel.Excel.shuiguobuff(n.citiaoshuzhitype);
      if (-1 != n.citiaochuxian) {
        this.tipView.getChildByName("layout").getChildByName("layout").active = true;
        a.node.active = true;
        a.string = e.nowdata.count * r.value[0] + "%";
      } else {
        this.tipView.getChildByName("layout").getChildByName("layout").active = false;
      }
      this.setCiTiaoContent(i, n, e.nowdata.count);
      this.tipView.active = true;
      EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.GAME_SHOW_CLICK, 1);
      this.nowshoId = e.nowdata.id;
    } else {
      this.nowshoId = -1;
      this.tipView.active = false;
    }
  };
  _creator.prototype.setCiTiaoContent = function (e, t) {
    var o = t.citiaomiaoshu;
    var n = Excel.Excel.shuiguobuff(t.citiaoshuzhitype);
    var i = (o = CommonUtils.default.replaceSymbols(o, "n", [""])).split("X");
    var a = "";
    for (var r = 0; r < i.length; r++) {
      var c = i[r];
      if (n.value[r] && r < i.length - 1) {
        a += "<color=#ffffff>" + c + "</c><color=#00ff00>" + n.value[r] + "</color>";
      } else {
        a += "<color=#ffffff>" + c + "</c>";
      }
    }
    a = "<outline color=#000000 width = 4>" + a + "</outline>";
    e.string = a;
  };
  _creator.prototype.onDisable = function () {
    EventManager.EventMgr.rmEventListener(EvenType.EVENT_TYPE.Game_Hide, this.closeTipView, this);
    EventManager.EventMgr.rmEventListener(EvenType.EVENT_TYPE.Game_Add_CiTiao, this.onAddListener, this);
  };
  _creator.prototype.updateUi = function (e, t) {
    this.rolelevel.string = "Lv." + e;
    this.progress.progress = t;
  };
  __decorate([_property(cc.Node)], _creator.prototype, "tipView", undefined);
  __decorate([_property(cc.Label)], _creator.prototype, "rolelevel", undefined);
  __decorate([_property(cc.ProgressBar)], _creator.prototype, "progress", undefined);
  return __decorate([_ccclass], _creator);
}(ResKeeper.default);
exports.default = _def_UI_SkillShow;